package study.函数式接口.比较器复合;

import study.User;
import study.Utils;
import study.函数式接口.Apple;

import java.util.Comparator;
import java.util.List;

import static java.util.Comparator.comparing;

/**
 * @Author 金贵权
 * @Date 2023/6/16 9:48
 **/
public class Demo01 {
    public static void main(String[] args) {
        Comparator<Apple> c = comparing(Apple::getWeight);
        Comparator<Apple> reversed = comparing(Apple::getWeight).reversed();
        Comparator<Apple> comparator = comparing(Apple::getWeight).reversed().thenComparing(Apple::getColor);

        /*comparing方法返回Comparator<>*/
        List<User> userList = Utils.getUserList();
        userList.sort(comparing(User::getName));
        System.out.println(userList);

        Comparator<Integer> result = (a,b)->a.compareTo(b);
        System.out.println(result.compare(1,2));;
    }
}
